package com.ajz.common.utils;

import org.springframework.security.core.context.SecurityContextHolder;

import com.ajz.security.model.SecurityUser;


public class UserUtils {

	public static String getUserNameWithLoginName() {
		SecurityUser user = (SecurityUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String username = String.format("[%s]%s", user.getLoginName(), user.getName());
		return username;
	}
	
	
	public static SecurityUser getUser() {
		SecurityUser user = (SecurityUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		return user;
	}
	
	public static String getUserLoginName(){
		String loginName="";
		try {
			SecurityUser user = (SecurityUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
			if (user!=null) {
				loginName=user.getLoginName();
			}
		} catch (Exception e) {
			
		}
		return loginName;
	}
	
	public static String getUserName(){
		SecurityUser user = (SecurityUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		return user.getUsername();
	}
	
}
